package com.lzh.lojcodesandbox.unsafe;

import java.io.*;

/**
 * 运行其他程序（比如危险木马）
 * @Author luzhiheng
 * @Date 2023/8/31 9:50
 */
public class RunFileError {
    public static void main(String[] args) throws InterruptedException, IOException {
        String userDir = System.getProperty("user.dir");
        String filePath = userDir + File.separator + "src/main/resources/木马程序.bat";
        Process process = Runtime.getRuntime().exec(filePath);
        process.waitFor();
        // 分批获取进程的输出
        InputStream is = process.getInputStream();
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
        // 逐行输出
        String compileOutputLine;
        while ((compileOutputLine = bufferedReader.readLine()) != null) {
            System.out.println(compileOutputLine);
        }
        System.out.println("执行程序成功");
    }
}
